<?php
if ($id == "") {
    $div_style = '';
} else {
    $div_style = '';
}
$get_view = ((!empty($_GET['view'])) ? $_GET['view'] : '');
$get_id = ((!empty($_GET['id'])) ? $_GET['id'] : '');
if (empty($_SESSION['province_id'])) {
    header("Location: " . base_url . 'account/edit_seller.php?error=USER_PROFILE_UPDATE_REQUIT&backto='.urlencode($CURRENT_URL));
    exit();
}
?>
<style>
    .box {
        margin-bottom: 15px;
    }
    .box > .heading {
        height: 38px;
        padding-left: 7px;
        padding-right: 7px;
        border: 1px solid #DBDBDB;
        background: url('../image/box.png') repeat-x;
        -webkit-border-radius: 7px 7px 0px 0px;
        -moz-border-radius: 7px 7px 0px 0px;
        -khtml-border-radius: 7px 7px 0px 0px;
        border-radius: 7px 7px 0px 0px;
        height: 50px;
    }
    .box > .heading h1 {
        margin: 0px;
        padding: 11px 0px 0px 0px;
        color: #537014;
        font-size: 16px;
        float: left;
    }
    .box > .heading h1 img {
        margin-top: -1px;
        margin-left: 3px;
        margin-right: 8px;
    }
    .box > .heading .buttons {
        float: right;
        padding-top: 7px;
        margin-right: 5px;
    }
    .box > .heading .buttons .button {
        margin-left: 5px;
    }
    .box > .content h2 { 
        text-transform: uppercase;
        color: #FF802B;
        font-size: 15px;
        font-weight: bold;
        padding-bottom: 3px;
        border-bottom: 1px dotted #000000;	
    }
    .box > .content {
        padding: 10px;
        border-left: 1px solid #CCCCCC;
        border-right: 1px solid #CCCCCC;
        border-bottom: 1px solid #CCCCCC;
        min-height: 300px;
    }
    .required{
    	color:red;
    }
</style>
<script type="text/javascript">
    var selHtml = '';
    jQuery(document).ready(function($) {
        /* start append 4 field in reference maintenace */
            var MaxInputs       = 8; //maximum input boxes allowed
            var InputsWrapper   = $("#morefield"); //Input boxes wrapper ID
            var AddButton       = $("#addfield"); //Add button ID

            var x = InputsWrapper.length; //initlal text box count
            var FieldCount=1; //to keep track of text box added

            $(AddButton).click(function (e)  //on add input button click
            {
                    if(x <= MaxInputs) //max input box allowed
                    {
                        FieldCount++; //text box added increment
                        //add input box
                        $(InputsWrapper).append('<div id="uploadimage"><input type="file" name="imagefile[]" id="field_'+ FieldCount +'" value="Text '+ FieldCount +'"/><a href="#" class="removeclass"><img src="<?php echo base_url;?>templates/image/remove.png"/></a></div>');
                        x++; //text box increment
                    }
            return false;
            });

            $("body").on("click",".removeclass", function(e){ //user click on remove text
                    if( x > 1 ) {
                            $(this).parent('div').remove(); //remove text box
                            x--; //decrement textbox
                    }
            return false;
            });


        $("#btnsearch").click(function() {
            var txtpro_name = document.frmadd.pro_name.value;

            if (txtpro_name == "") {
                alert("Please input text to search!");
                document.forms['frmadd']['pro_name'].focus();
                return false;
            }

            $('#imgLoading').removeClass('hide');
            //alert(txtpro_name);
            $.ajax({
                type: "GET",
                url: "process.php",
                data: "action=search_pro&searchword=" + txtpro_name,
                success: function(message) {
                    $('#result').html(message);
                    $('#result').show();
                    $('#imgLoading').addClass('hide');
                    $(".addproduct").click(function() {
                        var pro_id = $(this).attr("id");
                        $('#formaddnew').hide();
                        $('#Loading').removeClass('hidel');
                        $.ajax({
                            type: "GET",
                            url: "process.php",
                            data: "action=diplayexist&id=" + pro_id,
                            success: function(message) {
                                $('#result').hide();

                                $('#showaddproduct').html(message);
                                $('#Loading').addClass('hidel');

                            }
                        });
                    });
                }
            });

        });

    });
</script>
<script type="text/javascript">
    function checkSellerform() {
        var textdes = tinyMCE.get('txtdesc').getContent();
        var product_name = document.forms['frmadd']['new_proname'].value;
        var select_type = document.forms['frmadd']['selectType'].value;
        if (!checkeditems(document.forms['frmadd'])) {
            $("#selectCate").click();
            return false;
        }
        else if (product_name == null || product_name == "") {
            alert("Please input Product Name!");
            document.forms['frmadd']['new_proname'].focus();
            return false;
        } else if (select_type == null || select_type == "") {
            alert("Please Select Product Type!");
            document.forms['frmadd']['selectType'].focus();
            return false;
        }
        var selValid = true;
        $('.selectCon').each(function(i) {
            if ($(this).find("option:selected").val() == "") {
                alert("Please select country!");
                $(this).focus();
                selValid = false;
                return false;
            } else if ($(".txtprice:eq(" + i + ")").val() == "") {
                alert("Please input price!");
                $(".txtprice:eq(" + i + ")").focus();
                selValid = false;
                return false;
            } else if ($(".labor:eq(" + i + ")").val() == "") {
                alert("Please input laboratory!");
                $(".labor:eq(" + i + ")").focus();
                selValid = false;
                return false;
            }
        });


        if (selValid == false) {
            return false;
        } else if (textdes == null || textdes == "") {
            alert("Please Input Product Description!");
            $("#displaypopup").click();
            return false;
        }
        else {
            document.forms['frmadd'].submit();
        }
    }
</script>
<div class="breadcrumb">
    <a class="lever_1" style="z-index:100" href="<?php echo base_url; ?>"><?php echo $lang['HOME']; ?></a>
    <a class="lever_2" style="z-index:99" href="<?php echo base_url;?>account"><?php echo $lang['SELL_DASH'];?></a>
    <a class="lever_3" style="z-index:98" href="<?php echo base_url; ?>account/product"><?php echo $lang['MANAG_PRO']; ?></a>
    <?php if ($get_view == 'add') { ?>
        <a class="lever_4" style="z-index:97" href="<?php echo base_url; ?>account/product/index.php?view=add"><?php echo $lang['UR_NEW_PRO']; ?></a>
    <?php } else { ?>
        <a class="lever_4" style="z-index:97" href="<?php echo base_url; ?>account/product/index.php?view=edit&id=<?php echo $get_id; ?>"><?php echo $lang['EDIT']; ?></a>
    <?php } ?>
</div>
<div class="box">
    <div class="row-fluid">
        <div class="span12">
            <form class="form-search span12" action="<?php echo base_url; ?>account/product/process.php?action=add" name="frmadd" id="frmadd" enctype= "multipart/form-data" method="post" onsubmit="return checkSellerform();">
                    <table cellpadding="0" cellspacing="0" borwder="0" width="100%" style="padding-left:10px;">
                        <tr>
                            <td colspan="2">
                                <?php
                                $reachedPost = user_reached_post();
                                if ($reachedPost == TRUE):
                                    header("Location: " . base_url . 'account/selectAccountType.php?error=USER_LIMIT');
                                    exit();
                                else:
                                    
                                    if ($id == "") {
                                        echo '<div class="box">';
                                        require_once(S_ROOT . '/admin/product/formadd.php');
                                        echo '</div>';
                                    } else {
                                        require_once(S_ROOT . '/admin/product/formedit.php');
                                    }
                                    
                                endif;
                                ?>
                            </td>
                        </tr>
                        <style type="text/css">
                            .hide{
                                display: none;
                            }
                            .hidel{
                                display: none;
                            }
                        </style>
                        <tr>
                            <td>
                                <img src="ajax-loader.gif" id="imgLoading" border="0" class="hide" />
                                <div id="result"></div>
                            </td>
                        </tr>
                        <tr>
                            <td height="25">&nbsp;</td>
                        </tr>
                    </table>
                    <div class="clear"></div>
                    <a name="1"></a>
                    <img src="ajax-loader.gif" id="Loading" border="0" class="hidel" />
                    <div id="showaddproduct"></div>
            </form>

        </div> 

        <!-- <div class="twelve columns">
        <?php
        //include('../left.php');
        ?>
        </div>--><!--<div class="three columns">--> 

    </div><!--<div class="row">-->
</div>
<script type="text/javascript" src="<?php echo base_url; ?>admin/templates/javascript/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<?php echo base_url; ?>templates/javascripts/tabs.js"></script>
<script>
    $('#tabs a').tabs();
</script>